package com.cjbdi.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class PropertiesUtil {
	private static String FILEPATH = "manager.properties";
	private static Map<String,String> map = new HashMap<String,String>();
	public static String getProperty(String key){
		if(map.size()==0){
			init(FILEPATH);
		}
		return map.get(key);
	}
	
	/**
	 * 获取某配置文件中的配置
	 * @param filepath
	 * @return
	 */
	private static boolean init(String filePath){
		try {
			Properties pro = new Properties();
			pro.load(PropertiesUtil.class.getClassLoader().getResourceAsStream(filePath));
			Set<Object> keys = pro.keySet();
			for(Object o:keys){
				String key = (String)o;
				String value = pro.getProperty(key);
				map.put(key, value);
			}
		} catch (Exception e) {
            System.out.println("配置文件读取失败");
            return false;
		}
		return true;
	}
}
